// Problem 036: Double-base palindromes
// The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
// Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
// (Please note that the palindromic number, in either base, may not include leading zeros.)

package main

import (
	"fmt"
	"projecteuler/euler"
)

func p036() {
	ans := 0
	for n := 1; n < 1000; n++ {
		m := getPalindrome(n)
		for _, v := range m {
			if v%2 != 0 && euler.IsPalindrome(v, 2) {
				ans += v
			}
		}
	}
	fmt.Println("Problem 036:", ans)
}

func getPalindrome(n int) []int {
	s, t := n, n/10
	for n > 0 {
		s = s*10 + n%10
		t = t*10 + n%10
		n /= 10
	}
	return []int{s, t}
}
